<!DOCTYPE html>
<html>
	<head>
    <meta charset="UTF-8">
    <title>后台系统-登陆</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="css/login.css" type="text/css">
	<style>
		body {
			background: url(img/yi.jpg) 0% 0% / cover no-repeat;
			position: static;
			font-size: 12px;
		}
		
		input:-webkit-autofill {
			/* 取消Chrome记住密码的背景颜色 */
			-webkit-box-shadow: 0 0 0 1000px white inset !important;
		}
		
		html {
			height: 100%;
		}
	</style>
</head>
<body>
<div class="main-body">
    <div class="login-main">
        <div class="login-top">
            <span>医院药品管理系统</span>
        </div>
        <form class="layui-form login-bottom">
            <div class="center">
                <div class="item">
                    <span class="layui-icon layui-icon-username"></span>&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" name="userAcc" placeholder="请输入登录账号" maxlength="24">
                </div>

                <div class="item">
                    <span class="layui-icon layui-icon-password"></span>&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="password" name="userPass" placeholder="请输入密码" maxlength="20">
                </div>

            </div>
			
            <div class="layui-form-item" style="text-align:center; width:100%;height:100%;margin:0px;">
                <button class="login-btn" lay-submit="" lay-filter="login">立即登录</button>
            </div>
			
        </form>
    </div>
</div>
<div class="footer">
    @版权所有 designed by liucong 2020
</div>
<script src="layui/layui.js"></script>
<script>
    layui.use(['form','jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

        // 进行登录操作
        form.on('submit(login)', function (data) {
            var mes = data.field;
            if (mes.userAcc == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (mes.userPass == '') {
                layer.msg('密码不能为空');
                return false;
            }
			
			console.log(mes);
			// alert(mes)
			
			$.ajax({
				type:"post",
				url:"http://localhost:8081/user/login",
				async:true,
				contentType:"application/json;charset=UTF-8",
				data:JSON.stringify(mes),
				xhrFields: {
					withCredentials: true
				},
				success:function(res){
					sessionStorage.setItem("userName",res.data);
					console.log(res);
					if(res.code==1){
						layer.msg(res.msg, goAdmin());
					}else if(res.code==2){
						layer.msg(res.msg, goUser());
					}else if(res.code==-1){
						$('input').val("");
						layer.msg(res.msg);
					}
				}
			});
			
			function goAdmin(){
				//alert(111);
				window.location.href = 'mainAdm.html';
			}
			
			function goUser(){
				window.location.href = 'mainUser.html';
			}
			
            return false; //阻止表单跳转
        });
    });
</script>

</body>
</html>